import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../../../lib_baseview/lib_baseview.dart';
import '../../../../lib_baseview/utils/constant/text_styles.dart';
import '../../../../lib_runtime/utils/string_util.dart';
import '../../../m_chatroom.dart';

/// 房间麦位Widget
class RoomMicWidget extends StatefulWidget {
  // final SimpleChannelUserSlot? item;
  final double avatarSize;
  final Widget? emptyAvatar;
  final BoxBorder? border;

  const RoomMicWidget({
    super.key,
    // this.item,
    this.avatarSize = 50,
    this.emptyAvatar,
    this.border,
  });

  @override
  State<RoomMicWidget> createState() => _RoomMicWidgetState();
}

class _RoomMicWidgetState extends State<RoomMicWidget> {
  late RootProxyModel roomModel;

  @override
  void initState() {
    super.initState();

    roomModel = context.read<RootProxyModel>();
  }

  // Channel? get channel => roomModel.channel;

  int get position => -1;

  String get roleStr {
    return 'roleStr';
    // if (position == 0 && (channel?.showRoomOwner ?? false)) {
    //   return T.current!.homeowner;
    // }
    // switch (widget.item?.micType) {
    //   case MicTypeEnum.CAR_OWNER_MIC:
    //     return T.current!.driver;
    //   case MicTypeEnum.COMMON_MIC:
    //     return '';
    //   case MicTypeEnum.HOST_MIC:
    //     return T.current!.host;
    //   default:
    //     return '';
    // }
  }

  // Widget get avatar => MicAvatarWidget(
  //       item: widget.item,
  //       position: position,
  //       width: widget.avatarSize,
  //       border: widget.border,
  //     );

  Widget get nickName => SizedBox(
        width: widget.avatarSize,
        height: 12,
        child: OverflowBox(
          minWidth: widget.avatarSize,
          maxWidth: widget.avatarSize * 1.3,
          child: Container(
            width: widget.avatarSize * 1.3,
            height: 12,
            alignment: Alignment.center,
            child: const Text(
              // StringUtil.removeHideSpace(widget.item?.user.nickname ?? ''),
              'removeHideSpace',
              softWrap: false,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                  fontSize: 9,
                  fontWeight: FontWeight.w400,
                  color: Colors.white),
            ),
          ),
        ),
      );

  Widget get roleAndMic => Container(
        decoration: const ShapeDecoration(
          shape: StadiumBorder(),
          color: Color(0x14FFFFFF),
        ),
        margin: const EdgeInsets.only(top: 4),
        padding: const EdgeInsets.symmetric(horizontal: 4),
        height: 14,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            image(
              "ic_mic_on_wheat.svg",
              width: 7,
              fit: BoxFit.cover,
            ),
            if (counterTime > 0)
              Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  const SizedBox(
                    width: 4,
                  ),
                  Container(
                    width: 0.5,
                    height: 7,
                    color: Colors.white.withOpacity(0.3),
                  ),
                  const SizedBox(
                    width: 4,
                  ),
                  Text(
                    '${counterTime}s',
                    style: JRTextStyles.styleFont9W400,
                  )
                ],
              ),
            if (roleStr != null && counterTime <= 0) ...[
              const SizedBox(
                width: 2,
              ),
              Text(
                roleStr,
                style: const TextStyle(
                    fontSize: 8,
                    fontWeight: FontWeight.w500,
                    color: Colors.white,
                    height: 1),
              ),
            ],
          ],
        ),
      );

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        // avatar,
        const SizedBox(
          height: 4,
        ),
        nickName,
        roleAndMic,
        // widget.item?.hasUser() == true
        //     ? roleAndMic
        //     : const SizedBox(height: 18),
      ],
    );
  }

  ///倒计时
  int get counterTime {
    int time = 0;
    // if (widget.item?.hasUser() ?? false) {
    //   int timeNow = GlobalConfig.serverTime ~/ 1000;
    //   time = widget.item!.counterTimestamp - timeNow;
    // }
    return 10;
  }
}
